/*
 Estructura de datos que contiene la información en memoria de los eventos de cada mes.
 la información que se almacena es la siguiente.
 name: Nombre del evento
 description: Descripcion del evento
 day/month/year:fecha
 hourinit:hora de inicio.
 hourend:hora final
 idevent:identificador del usuario que esta utilizando el sistema.
 edit:indica si el usuario puede editar la el evento
 */
//alamcena todos los eventos
function lEvents()
{
	//contiene una lista de años
	var lYear;

	//contador
	var contyear;
	this.Create=function()
	{
		this.lYear= new Array(); 
		this.contyear=0;
	}
	//crea un nuevo año
	this.CreateYear=function(year)
	{
		exist=false;
		for(l=0;l<this.contyear;l++)
		{
			if (this.lYear[l].year == year) {
				exist = true;
				break;
			}
		}
		if (!exist) {
			this.lYear[this.contyear] = new yEvents();
			this.lYear[this.contyear].Create(year);
			this.contyear++;
		}
	}
	//agrega un nuevo evento
	this.addEvent=function(year,month,day,name,description,hourinit,hourend,place,edit,idevent)
	{
		this.CreateYear(year);
		for(l=0;l<this.contyear;l++)
		{
			if(this.lYear[l].year==year)
			{
				this.lYear[l].addMonthEvent(month,day,name,description,hourinit,hourend,place,edit,idevent);
				break;
			}
		}
	}
	//retorna los eventos de un dia
	this.getDayEvents=function(year,month,day)
	{
		for(l=0;l<this.contyear;l++)
		{
			if(this.lYear[l].year==year)
			{
				return this.lYear[l].getDayEvents(month,day);
				break;
			}
		}
	}
	//retorna los eventos de un mes
	this.getMonthEvents=function(year,month)
	{
		try {
	for(l=0;l<=this.contyear;l++)
		{
			if(this.lYear[l].year==year)
			{
				return this.lYear[l].getMonth(month);
				break;
			}
		}
		} catch (e) {
		return null;	
		}


	}
}
//alamcena los eventos de un año
function yEvents()
{
	//lista de los dias
	var lmEvents;
	//Año del evento
	var year;
	//puntero
	var next;
	//contructor
	this.Create =function(year)
	{
		this.year=year;
		this.next=null;
	}
	//crea un nuevo dia
	this.CreateMonth=function(month)
	{
		if(this.lmEvents==null)
		{
			this.lmEvents=new mEvents();
			this.lmEvents.Create(month);
		}else
		{
			//verifica si el dia existe para crearlo
			if(this.getMonthEvents(month)==null)
			{
				_month=new mEvents();
				_month.Create(month);
				_month.next=this.lmEvents;
				this.lmEvents=_month;
			}
		}
	}
	//busca  retorna los eventos de un dia
	this.getMonthEvents=function(month)
	{
		listmonths=this.lmEvents;
		while(listmonths!=null)
		{
			if(listmonths.month==month)
				return listmonths;
				
			listmonths=listmonths.next;
		}
		return null;
	}
	//busca  retorna los eventos de un dia
	this.getMonth=function(month)
	{
		listmonths=this.lmEvents;
		while(listmonths!=null)
		{
			if(listmonths.month==month)
				return listmonths.ldEvents;
				
			listmonths=listmonths.next;
		}
		return null;
	}
	//Elimina un dia de la lista
	this.removeMonthEvents=function(month)
	{
		if(lmEvents.month=month)
		{
			return lmEvents.netx;
		}else
		{
			listmonths=this.lmEvents;
			lmonths=null;
			while(listmonths!=null)
			{
				if(lmonths==null)
				{
					lmonths = listmonths;
	                lmonths.next = null;
				}else
				{
					lmonths.next=listmonths;
				}
				listmonths=listmonths.next;
			}
			this.ldEvents=lmonths;
		}
	}
	//agrega un nuevo evento al dia correspondiente
	this.addMonthEvent=function(month,day,name,description,hourinit,hourend,place,edit,idevent)
	{
		this.CreateMonth(month);
		_month=this.getMonthEvents(month);
		_month.addDayEvent(day,name,description,hourinit,hourend,place,edit,idevent);
		//this.removeDayEvents(day);
	}
	//obtiene la información de un dia
	this.getDayEvents=function(month,day)
	{
		xmonth=this.getMonthEvents(month);
		try {
			return xmonth.getDayEvents(day);
		} catch (e) {
			return null;	
		}


	}
	
}
//alamcena los eventos por mes
function mEvents()
{
	//lista de los dias
	var ldEvents;
	//mes del evento
	var month;
	//puntero
	var next;
	//contructor
	this.Create =function(month)
	{
		this.month=month;
		this.next=null;
	}
	//crea un nuevo dia
	this.CreateDay=function(day)
	{
		if(this.ldEvents==null)
		{
			this.ldEvents=new dEvents();
			this.ldEvents.Create(day);
		}else
		{
			//verifica si el dia existe para crearlo
			if(this.getDay(day)==null)
			{
				_day=new dEvents();
				_day.Create(day);
				_day.next=this.ldEvents;
				this.ldEvents=_day;
			}
		}
	}
	//busca  retorna los eventos de un dia
	this.getDay=function(day)
	{
		listdays=this.ldEvents;
		while(listdays!=null)
		{
			if(listdays.day==day)
				return listdays;
			listdays=listdays.next;
		}
		return null;
	}
	//Elimina un dia de la lista
	this.removeDay=function(day)
	{
		if(this.ldEvents.day==day)
		{
			this.ldEvents=this.ldEvents.netx;
		}else
		{
			listdays=this.ldEvents;
			ldays=null;
			while(listdays!=null)
			{
				if(ldays==null)
				{
					ldays = listdays;
	                ldays.next = null;
				}else
				{
					ldays.next=listdays;
				}
				listdays=listdays.next;
			}
			this.ldEvents=ldays;
		}
	}
	//agrega un nuevo evento al dia correspondiente
	this.addDayEvent=function(day,name,description,hourinit,hourend,place,edit,idevent)
	{
		this.CreateDay(day);
		_day=this.getDay(day);
		_day.addEvent(name,description,hourinit,hourend,place,edit,idevent);
		this.removeDay(day);
		if(this.ldEvents!=null){
			_day.next=this.ldEvents;
			this.ldEvents=_day;
		}else
		{
			this.ldEvents=_day;
		}
	}
	this.getDayEvents=function(day)
	{
		day=this.getDay(day);
		
		try {
			return day.lEvents;
		} catch (e) {
			return null;	
		}


	}
	
}
//alamcena los eventos por dias
function dEvents(){
	//lista de eventos del dia.
	var lEvents
	//dia del evento
	var day;
	//puntero de los eventos
	var next;
	//constructor
	this.Create = function(day)
	{
		this.next=null;
		this.day=day;
	}
	//agrega un nuevo evento al dia
	this.addEvent=function(name,description,hourinit,hourend,place,edit,idevent)
	{
		if(this.lEvents==null)
		{
			this.lEvents= new Events();
			this.lEvents.Create(name,description,hourinit,hourend,place,edit,idevent);
		}else
		{
			var event= new Events();
			event.Create(name,description,hourinit,hourend,place,edit,idevent);
			event.next=this.lEvents;
			this.lEvents=event;
		}
	}
	//retorna los eventos de un dia
	this.getEvents=function(day)
	{
		listE=this.lEvents;
		while (listE!=null)
		{
			if (listE.day=day)
				return ListE;
			
			listE=listE.next;	
		}
		return null;
	}

} 
//almacena la informacación de los eventos
function Events()
{
	//nombre del evento
	var name;
	//descripcion del evento
	var description;
	//hora de inicio
	var hourinit;
	//hora final
	var hourend;
	//lugar del evento
	var place;
	//indica si el usuario puede editar el evento
	var edit;
	//identificador del usuario
	var idevent;
	this.Create=function(name,description,hourinit,hourend,place,edit,idevent)
	{
		this.name=name;
		this.description=description;
		this.hourinit=hourinit;
		this.hourend=hourend;
		this.place=place;
		this.edit=edit;
		this.idevent=idevent;
	}
}
